package actionbar;

import android.content.res.Resources;       

import actionbar.TabAdapter;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.example.android.wifidirect.R;

import com.example.android.wifidirect.DeviceDetailFragment;
import com.example.android.wifidirect.DeviceListFragment;
import com.example.android.wifidirect.VideoDownload.*;

public class ActionBarController {
	ActionBar bar; //actionbar
	TabAdapter tabAdapter;//adapt
	Resources resources;
	ActionBar.Tab[] tabs;
	String[] tags;
	public ActionBarController(ActionBar actionBar, SherlockFragmentActivity activity){
		this.bar=actionBar;
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		resources = activity.getResources();
		tags = new String[3];
		tags[0]=resources.getString(R.string.device_detail);
		tags[1]=resources.getString(R.string.device_list);
		tags[2]=resources.getString(R.string.download);
		//tags[3]=resources.getString(R.string.rssi);
		
		tabs = new ActionBar.Tab[3];
		for(int i=0;i<3;i++){
			tabs[i] = bar.newTab();
			tabs[i].setText(tags[i]);
			tabs[i].setTag(tags[i]);
		}
        tabs[0].setTabListener(new TabAdapter(tags[0],activity,DeviceDetailFragment.class));  
        tabs[1].setTabListener(new TabAdapter(tags[1],activity,DeviceList.class));  
        tabs[2].setTabListener(new TabAdapter(tags[2],activity,download_fragment.class)); 
       // tabs[3].setTabListener(new TabAdapter(tags[3],activity,rssifragment.class)); 
        for(int i=0;i<3;i++){
        	bar.addTab(tabs[i]);
        }
	}
	public void goRight(){
		if(bar.getSelectedTab().getTag().equals(tags[0])){
			bar.selectTab(tabs[1]);
		}
		else if(bar.getSelectedTab().getTag().equals(tags[1])){
			bar.selectTab(tabs[2]);
		}
		/*else if(bar.getSelectedTab().getTag().equals(tags[2])){
			bar.selectTab(tabs[3]);
		}
		*/
		else{
		
			return;
		}
	}
	public void goLeft(){
		if(bar.getSelectedTab().getTag().equals(tags[0])){
			return;
		}
		else if(bar.getSelectedTab().getTag().equals(tags[1])){
			bar.selectTab(tabs[0]);
		}
		else if(bar.getSelectedTab().getTag().equals(tags[2])){
			bar.selectTab(tabs[1]);
		}
	/*
		else{
			bar.selectTab(tabs[2]);
		}
		*/
	}
}
